﻿using System;
using System.Xml.Linq;

namespace Phoenix.Xna.Framework.Serialization.Markup.Objects
{
    /// <summary>
    /// Base class for IMarkupObjects.
    /// </summary>
    internal abstract class MarkupObjectBase : IMarkupObject
    {
        #region IMarkupElement Members

        /// <summary>
        /// Gets or sets the SerializationService that provides context to references, etc.
        /// </summary>
        public Serializer Serializer { get; set; }

        /// <summary>
        /// Serialize the element to XML.
        /// </summary>
        /// <returns>The element markup serialzed as an XElement.</returns>
        public abstract XElement Serialize();

        /// <summary>
        /// Deserialize the element from an XElement.
        /// </summary>
        /// <param name="element">The XElement to deserialize this element from.</param>
        public abstract void Deserialize(XElement element);

        #endregion

        #region IMarkupObject Members

        /// <summary>
        /// Gets the object that is defined by this instance.
        /// </summary>
        public virtual object Instance { get; protected set; }

        /// <summary>
        /// Gets or sets the System.Type of the defined object.
        /// </summary>
        public virtual Type ObjectType { get; set; }

        /// <summary>
        /// Convert this MarkupObject in to an object model and sets the Instance.
        /// </summary>
        public abstract void ConstructInstance();

        /// <summary>
        /// Extract the markup information from the specified object.
        /// </summary>
        /// <param name="instance">The instance to extract markup information for.</param>
        public abstract void ExtractMarkup(object instance);

        #endregion
    }
}
